//获得用户权限
export const getSetting=()=>{
  return new Promise((resolve,reject)=>{
      wx.getSetting({
          success: (result) => {
              resolve(result);
          },
          fail: (err) => {
              reject(err);
          }
      });
  });
}

//打开用户授权
export const openSetting=()=>{
  return new Promise((resolve,reject)=>{
      wx.openSetting({
          success: (result) => {
              resolve(result);
          },
          fail: (err) => {
              reject(err);
          }
      });
  });
}

//获得用户地址
export const chooseAddress=()=>{
  return new Promise((resolve,reject)=>{
      wx.chooseAddress({
          success: (result) => {
              resolve(result);
          },
          fail: (err) => {
              reject(err);
          }
      });
  });
}

//弹出是否确认框
export const showModal=(content)=>{
  return new Promise((resolve,reject)=>{
      wx.showModal({
          title: '提示',
          content: content,
          showCancel: true,
          cancelText: '取消',
          cancelColor: '#000000',
          confirmText: '确定',
          confirmColor: '#3CC51F',
          success: (result) => {
              resolve(result.confirm);
          },
          fail: (err) => {
              reject(err);
          }
      });
        
  });
}

//提示框
export const showToast=(content)=>{
  return new Promise((resolve,reject)=>{
      wx.showToast({
          title: content,
          icon:"none",//success,loading
          success: (result) => {
              resolve(result);
          },
          fail: (err) => {
              reject(err);
          }
      });
  });
}

//调用微信登录接口
export const login=()=>{
  return new Promise((resolve,reject)=>{
      wx.login({
          timeout:10000,
          success: (result) => {
              resolve(result);
          },
          fail: (err) => {reject(err);}
      });
  });
}

//图片上传
export const uploadFile=(param)=>{
  return new Promise((resolve,reject)=>{
      wx.uploadFile({
          url: param.url,//远程服务器url
          filePath: param.filePath,//本地图片路径
          name: param.name,//image,表单的name属性
          formData: param.formData,
          header:param.header,
          success: (result) => {
            resolve(result);
          },
          fail: (err) => {
              reject(err);
          }
        });
  });
}
